import { get_patient_guidance_record } from '@/services/patient';
import { ProColumns, ProTable } from '@ant-design/pro-components';
import { Tooltip } from 'antd';
import { useRef } from 'react';

type GithubIssueItem = {
  id: string;
  old_phone: string;
  visitor_name: string;
  actual_time: string;
  visitor_type: string;
  visitor_time: string;
  content: number;
  call_type: number;
  guidance_content: string;
};
interface Iprops {
  patientId: number | undefined;
}
const GuidanceRecord = (props: Iprops) => {
  const actionRef = useRef();
  const { patientId } = props;

  // 获取患者指导记录
  const get_schedulinglist = async (params: {
    pageSize?: number | undefined;
    current?: number | undefined;
    keyword?: string | undefined;
  }) => {
    let request_body = {
      ...params,
      current: params.current,
      pageSize: params.pageSize,
      patient_id: patientId,
    };
    let res = await get_patient_guidance_record(request_body);
    console.log('患者指导记录', res);

    return {
      data: res.data.list,
      success: true,
      total: res.data.total_count,
    };
  };

  // 指导记录列表字段
  const columns: ProColumns<GithubIssueItem>[] = [
    {
      title: '序号',
      dataIndex: 'index',
      align: 'center',
      valueType: 'index',
    },
    {
      title: '指导账号',
      dataIndex: 'user_phone',
      align: 'center',
      key: 'user_phone',
    },
    {
      title: '指导医生',
      dataIndex: 'user_name',
      align: 'center',
      key: 'user_name',
    },
    {
      title: '指导时间',
      dataIndex: 'guidance_time',
      align: 'center',
      key: 'guidance_time',
    },
    {
      title: '指导内容',
      dataIndex: 'guidance_content',
      align: 'center',
      key: 'guidance_content',
      render: (_, record) =>
        record.guidance_content.length >= 5 ? (
          <Tooltip title={record.guidance_content}>
            <div>{record.guidance_content.substring(0, 5) + '...'}</div>
          </Tooltip>
        ) : (
          record.guidance_content
        ),
    },
  ];
  return (
    <div>
      <ProTable
        columns={columns}
        actionRef={actionRef}
        request={async (params = {}, sort, filter) => get_schedulinglist(params)}
        rowKey={(record) => record.id}
        search={false}
        toolBarRender={false}
        size="middle"
        pagination={{
          pageSize: 10,
          showSizeChanger: false,
        }}
        dateFormatter="string"
      />
    </div>
  );
};
export default GuidanceRecord;
